/*
 * @Author: 梁青春
 * @Date: 2025-11-04 09:36:05
 * @LastEditTime: 2025-11-19 09:19:55
 * @LastEditors: 梁青春
 */
import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import AutoImport from 'unplugin-auto-import/vite'
import setupExtend from 'unplugin-vue-setup-extend-plus/vite'

const baseUrl = 'http://8.131.103.17:9009' // 后端接口
// const baseUrl = 'http://192.168.1.47:8080' // 后端接口

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src'),
        '~': resolve('src/renderer'),
        '@': resolve('src/renderer/src')
      },
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
    },
    plugins: [
      vue(),
      AutoImport({
        imports: ['vue', 'vue-router', 'pinia'],
        eslintrc: {
          enabled: false,
          filepath: './.eslintrc-auto-import.json',
          globalsPropValue: true
        }
      }),
      setupExtend({}),
      createSvgIconsPlugin({
        iconDirs: [resolve('src/renderer/src/assets/icons/svg')],
        symbolId: 'icon-[dir]-[name]',
        svgoOptions: true
      })
    ],
    server: {
      port: 8097,
      host: true,
      proxy: {
        '/dev-api': {
          target: baseUrl,
          changeOrigin: true,
          rewrite: p => p.replace(/^\/dev-api/, '')
        },
        '^/v3/api-docs/(.*)': {
          target: baseUrl,
          changeOrigin: true
        }
      }
    },
    css: {
      postcss: {
        plugins: [
          {
            postcssPlugin: 'internal:charset-removal',
            AtRule: {
              charset: atRule => {
                if (atRule.name === 'charset') {
                  atRule.remove()
                }
              }
            }
          }
        ]
      }
    }
  }
})
